
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;

namespace Swaf.Messaging
{
	/// <summary>
	/// Summary description for IMessageHelper.
	/// </summary>
	public interface IMessagingSystem
	{
		/// <summary>
		/// Remembers connection info about a messaging system connection so that later calls to send or receive a message can just use the
		/// unique key rather then lots of params for the messaging system.
		/// </summary>
		/// <param name="key">The unique key to use for the new entry into the connection catalog</param>
		/// <param name="connectionInfo">The connection info to be remembered</param>
		void defineConnection(string key, IMessagingConnectionInfo connectionInfo);

		/// <summary>
		/// Retrieves connection info from the connection info catalog
		/// </summary>
		/// <param name="key">The unique key to find the connection info</param>
		/// <returns>The connection info for the given key or null if none exists with that key</returns>
		IMessagingConnectionInfo getConnectionInfo(string key);

		/// <summary>
		/// Removes a connection info from the connection catalog
		/// </summary>
		/// <param name="key">The unique key to remove from the catalog</param>
		/// <returns>The connection info removed or null if none existed with the given key</returns>
		IMessagingConnectionInfo removeConnectionInfo(string key);

		/// <summary>
		/// The connection catalog of Key/IMessagingConnectionInfo pairs.
		/// </summary>
		IDictionary ConnectionDefinitions{get;}

		void send(string msgBody, IDictionary messageProperties, string encrypt,string destination, string connectionName, string messageProtocolFormat, Swaf.Container.INameAddressSupport info);
		void send(string msgBody, string encrypt,string destination, string connectionName, string messageProtocolFormat, Swaf.Container.INameAddressSupport info);
		void send(string msgBody, string encrypt, IMessagingConnectionInfo connectionInfo);
		void send(string msgBody, string encrypt, IMessagingConnectionInfo connectionInfo, IDictionary messageProperties);
		void send(IMessage msg, IMessagingConnectionInfo connectionInfo);

		string send(string msgBody, IDictionary messageProperties, string encrypt, string destination, string connectionName, string messageProtocolFormat, Swaf.Container.INameAddressSupport info, string replyDestination, string replyQueueManager);
		string send(string msgBody, string encrypt, string destination, string connectionName, string messageProtocolFormat, Swaf.Container.INameAddressSupport info, string replyDestination, string replyQueueManager);

		/// <summary>
		/// Will send a message using the connectionKey param to get the connection info out of the connection catalog
		/// </summary>
		/// <param name="connectionKey">The key to use in the search of the connection catalog</param>
		/// <param name="msgBody"></param>
		/// <param name="messageProperties">Name/Value pairs of properties to be set on the underlying messaging system's message object before sending.</param>
		void send(string connectionKey, string msgBody, string encrypt, IDictionary messageProperties);


		/// <summary>Receive a message and return the message object
		/// </summary>
		/// <param name="">
		/// source - Where to pull the data from (For MQSeries, this is the queue name)
		/// </param>
		/// <param name="">
		/// queueManagerName - Name of the queue manager to use (Currently supported for MQSeries)
		/// </param>
		/// <param name="">
		/// connectionName - Currently not supported
		/// </param>
		/// <returns>
		/// IMessage object containing resulting message
		/// </returns>
		IMessage receive(string source, string connectionName);
		IMessage receive(string source, string connectionName, int timeoutInMS);
		IMessage receive(IMessagingConnectionInfo connectionInfo, int timeoutInMS);

		IMessage receive(string connectionKey, int timeoutInMS);

		void reply(string msgBody, string destination, IMessage originalMessage);

		void beginTrans(IMessagingConnectionInfo connection);
		void rollback(IMessagingConnectionInfo connection);
		void commit(IMessagingConnectionInfo connection);
	}
}
